﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.IO;

/*using CrystalDecisions.ReportAppServer.ReportDefModel;
//using CrystalDecisions.Reporting.WebControls;
using CrystalDecisions.CrystalReports.TemplateEngine;
//using CrystalDecisions.Web;
using CrystalDecisions.Shared;
//using CrystalDecisions.CrystalReports.Engine;*/


using prototype123.models;
using prototype123.data_access;


namespace prototype123.controllers
{
    // ViewCheckSheetReportController handles Generating a Checksheet for a given student
    // and printing it out in either HTML or PDF formats
    class ViewCheckSheetReportController
    {
        public void ExportToFile(string type)
        {

            TermItemDAO tidao = new TermItemDAO(Connector.Instance.Connection);
            //DataTable table = tidao.GetCheckSheetMaybe(SystemController.Instance.CurrentStudent.StudentID);
            //DataTable table = AddressEntryDAO.GetAccounts(partOfEmail.Text);

            //ViewChecksheetReport report = new ViewChecksheetReport();
            //AddressReport report = new AddressReport();
            //report.SetDataSource(table);

            //report.ExportOptions.ExportFormatType = (type == "PDF" ? CrystalDecisions.Shared.ExportFormatType.PortableDocFormat : CrystalDecisions.Shared.ExportFormatType.HTML40);

            string tempDir = Directory.GetCurrentDirectory();  //Server.MapPath("\\ReportGen\\"); //System.Configuration.ConfigurationManager.AppSettings["ReportGenDirectory"];
            string tempFileName = SystemController.Instance.CurrentStudent.FirstName + " " + SystemController.Instance.CurrentStudent.LastName;  //Session.SessionID.ToString() + ".";
            /*switch (type)
            {
                case "PDF":
                    tempFileName += "pdf";
                    break;
                case "HTML":
                    tempFileName += "htm";
                    CrystalDecisions.Shared.HTMLFormatOptions hop = new CrystalDecisions.Shared.HTMLFormatOptions();
                    hop.HTMLBaseFolderName = tempDir;
                    hop.HTMLFileName = tempFileName;
                    report.ExportOptions.FormatOptions = hop;
                    break;
            }*/

            /*CrystalDecisions.Shared.DiskFileDestinationOptions dfo = new CrystalDecisions.Shared.DiskFileDestinationOptions();
            dfo.DiskFileName = tempDir + tempFileName;
            report.ExportOptions.DestinationOptions = dfo;
            report.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
            string reportTempFileName = report.FileName.Split('\\')[report.FileName.Split('\\').Length - 1].Substring(0, report.FileName.Split('\\')[report.FileName.Split('\\').Length - 1].LastIndexOf("."));

            report.Export();
            report.Close();

            /*
            Response.ClearContent();
            Response.ClearHeaders();
            Response.ContentType = (type == "PDF" ? "application/pdf" : "text/html");

            Response.WriteFile(tempDir + (type == "PDF" ? "" : reportTempFileName + "\\") + tempFileName);
            Response.Flush();
            Response.Close();
            */
            //Console.WriteLine(reportTempFileName[0]);
        }


    }
}

